package com.xuzimian.globaldemo.spring.springwebflux.handler;

import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Mono;

/**
 * @program: global-demo
 * @description:
 * @author: xzm
 * @create: 2019-04-30 10:47
 **/
@Component
public class WebSocketDemoHandler implements WebSocketHandler {

    @Override
    public Mono<Void> handle(WebSocketSession session) {
        return session.send(
                session.receive().map(msg
                        -> session.textMessage(session.getId() + ":" + msg.getPayloadAsText() + " 你好！")));
    }

}